package com.tj.seed.common.context;

public class UserContextHolder {

    private static ThreadLocal<UserContext> holder = new ThreadLocal<>();

    public static void set(UserContext value) {
        holder.set(value);
    }

    public static UserContext get() {
        return holder.get();
    }

    public static void remove() {
        holder.remove();
    }

    public static Long getUserId() {
        return getUserContext().getUserId();
    }

    public static String getLoginName() {
        return getUserContext().getLoginName();
    }

    public static String getUserName() {
        return getUserContext().getUserName();
    }

    public static UserContext getUserContext() {
        UserContext userContext = holder.get();
        if (userContext == null) {
            userContext = new UserContext();
            holder.set(userContext);
            return userContext;
        }
        return userContext;
    }
}
